﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;

namespace MiniFox.Data.EntityFramework
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class EntityDataCommand<TEntity> : DataCommand<TEntity> where TEntity : class
    {
        DbContext _context;
        string _connectionString;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public EntityDataCommand(DbContext context)
        {
            _context = context;
        }
        /// <summary>
        /// 
        /// </summary>
        public override string ConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_connectionString))
                    _connectionString = this.CurrentDbContext.Database.GetConnectionString();
                return _connectionString;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected virtual DbContext CurrentDbContext
        {
            get { return _context; }
        }
    }
}
